/**
 * 
 */
package com.shine.icis.blo.imp;

import com.shine.cotrun.sql.QueryParameters;
import com.shine.cotrun.web.comm.ListPage;
import com.shine.icis.blo.IDepotBankInfoService;
import com.shine.icis.dao.IDepotBankInfoDAO;
import com.shine.icis.dto.DepotBankInfo;
import com.shine.icis.exception.ICISException;

/**
 * @author zsy
 *
 */
public class DepotBankInfoService implements IDepotBankInfoService {
	
	private IDepotBankInfoDAO depotBankInfoDAO;

	
	public void setDepotBankInfoDAO(IDepotBankInfoDAO depotBankInfoDAO) {
		this.depotBankInfoDAO = depotBankInfoDAO;
	}

	@Override
	public void addDepotBankInfo(String bankCode, String bankName, 
			String occurDate) throws ICISException {
		if (bankCode == null) {
			throw new IllegalArgumentException();
		}
		DepotBankInfo info = new DepotBankInfo();
//		DepotBankInfoId id = info.new DepotBankInfoId();
//		id.setCompanyCode(companyCode);
//		id.setBankCode(bankCode);
		if (!depotBankInfoDAO.checkId(bankCode)) {
			throw new ICISException("证券公司代码、银行代码不能重复");
		}
		info.setBankCode(bankCode);
		info.setBankName(bankName);
		info.setOccurDate(occurDate);
		info.setRecordNo(depotBankInfoDAO.findNextRecordNo());
		depotBankInfoDAO.save(info);
		
	}
	
	@Override
	public void modifyDepotBankInfo(String oldBankCode,
			String bankCode, String bankName, 
			String occurDate) throws ICISException {
		if (oldBankCode == null || oldBankCode == null) {
			throw new IllegalArgumentException();
		}
		DepotBankInfo info = new DepotBankInfo();
//		DepotBankInfoId id = info.new DepotBankInfoId();
//		id.setCompanyCode(companyCode);
//		id.setBankCode(bankCode);
		if (!(oldBankCode.equals(bankCode)) 
				&& !depotBankInfoDAO.checkId(bankCode)) {
			throw new ICISException("证券公司代码、银行代码不能重复");
		}
		info.setBankCode(bankCode);
		info.setBankName(bankName);
		info.setOccurDate(occurDate);
		
//		DepotBankInfoId oldId = info.new DepotBankInfoId();
//		oldId.setCompanyCode(oldCompanyCode);
//		oldId.setBankCode(oldBankCode);
		depotBankInfoDAO.update(oldBankCode, info);
		
	}

	@Override
	public void deleteDepotBankInfo(String bankCode) {
		if (bankCode == null) {
			return;
		}
//		DepotBankInfoId id = new DepotBankInfo().new DepotBankInfoId();
//		id.setCompanyCode(companyCode);
//		id.setBankCode(bankCode);
		depotBankInfoDAO.delete(bankCode);
		
	}

	@Override
	public ListPage<DepotBankInfo> getDeptInfoPage(QueryParameters qp) {
		if (qp == null) {
			throw new IllegalArgumentException();
		}
		return depotBankInfoDAO.findListPage(qp);
	}

}
